Originally Posted by
Salem
Really?
Code:
$ gcc -Wall foo.c
foo.c: In function ‘fileCheck’:
foo.c:18:9: warning: format ‘%s’ expects argument of type ‘char *’, but argument 3 has type ‘char (*)[100]’ [-Wformat]
foo.c:19:19: warning: comparison with string literal results in unspecified behavior [-Waddress]
foo.c:26:1: warning: control reaches end of non-void function [-Wreturn-type]
$ gcc --version
gcc (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
You can't compare strings with ==, you need to use strcmp()
The ; at the end of the line renders the if statement useless.
Got it, see revised code:
Code:
#include "main.h"
int fileCheck(FILE *fp)
{
int line_count = 0;
char file[BUFF];
char check[BUFF];
char new_line[] = "\n";
char *line;
regex_t regex;
/*if (regcomp(®ex, to_find, REG_EXTENDED) != 0)
{
fprintf(stderr, "Failed to compile regex '%s'\n", to_find);
return EXIT_FAILURE;
}*/
while (fgets(file, BUFF, fp) != NULL)
{
if (strcmp(file, new_line) == 0);
{
line_count++;
}
/*if (regexec(®ex, file, 0, NULL, 0) != 0)
{
printf("Digit: %s is not alphanumeric on line %d !\n", file, line_count);
return EXIT_FAILURE;
}*/
}
printf("Line count: %d\n", line_count);
}